package com.lenovo.lcdm.type.controller;

import com.lenovo.lcdm.common.model.ResponseVo;
import com.lenovo.lcdm.type.dto.AttributeFolderDTO;
import com.lenovo.lcdm.type.service.TypeAttributeFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xujing30
 * @desc 属性文件夹管理微服务对外接口
 * @date 2024-01-11
 */
@RestController
public class AttributeFolderController {
    @Autowired
    private TypeAttributeFolderService attributeFolderService;
   
    @GetMapping("/attribute-folder/root-folder")
    public ResponseVo<AttributeFolderDTO> queryRootFolder() {
        ResponseVo<AttributeFolderDTO> responseVo = new ResponseVo<>();
        AttributeFolderDTO data = attributeFolderService.queryRootFolder();
        responseVo.setData(data);
        return responseVo;
    }

    
    @GetMapping("/attribute-folder/root-folder/global-attributes")
    public ResponseVo<AttributeFolderDTO> queryFolderAttribute() {
        ResponseVo<AttributeFolderDTO> responseVo = new ResponseVo<>();
        AttributeFolderDTO data = attributeFolderService.queryFolderAttribute();
        responseVo.setData(data);
        return responseVo;
    }

   
    @PostMapping("/attribute-folder")
    public ResponseVo<AttributeFolderDTO> createFolder(@RequestParam(value = "name") String name, @RequestParam(value = "parentId") Long parentId) {
        ResponseVo<AttributeFolderDTO> responseVo = new ResponseVo<>();
        AttributeFolderDTO data = attributeFolderService.saveFolder(name, parentId);
        responseVo.setData(data);
        return responseVo;
    }


   
    @PutMapping("/attribute-folder")
    public ResponseVo updateFolder(@RequestParam(value = "name") String name, @RequestParam(value = "id") Long id) {
        ResponseVo<AttributeFolderDTO> responseVo = new ResponseVo<>();
        attributeFolderService.updateFolder(name, id);
        return responseVo;
    }


    
    @DeleteMapping("/attribute-folder")
    public ResponseVo deleteFolder(@RequestParam(value = "id") Long id) {
        ResponseVo responseVo = new ResponseVo<>();
        attributeFolderService.deleteFolder(id);
        return responseVo;
    }

}
